const joi = require("joi")
let _id = joi.string().required().error(new Error('_id为必填项'))
let username = joi.string().min(3).max(10).required().error(new Error('用户名长度为3-10个字符，且为必填项'))
let password = joi.string().min(6).max(16).regex(/^[a-zA-Z0-9]+$/).required().error(new Error('密码格式为6-16位不含特殊字符的字符串'))
let status = joi.boolean().required().error(new Error('用户状态格式不正确'))
let telephone = joi.string().regex(/^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/).error(new Error('电话格式不正确'))
let gender = joi.number().min(0).max(1).error(new Error('性别应为 0(男) 或 1(女)'))
let email = joi.string().regex(/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(.[a-zA-Z0-9_-]+)+$/).error(new Error('邮箱格式不正确'))
let idnumber = joi.string().regex(/^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/).error(new Error('身份证号码格式不正确'))

const UserSchema = {
    append: joi.object({ username, password, status, telephone, email, idnumber,gender }),
    update: joi.object({ _id, username, status, telephone, email, idnumber,gender })
}

module.exports = UserSchema